Skip to content

feat: add configurable stop timeout for ContainerGuard cleanup#228

Merged
joshrotenberg merged 1 commit intomainfrom
feat/container-guard-stop-timeout
Jan 6, 2026
Merged

feat: add configurable stop timeout for ContainerGuard cleanup#228
joshrotenberg merged 1 commit intomainfrom
feat/container-guard-stop-timeout

Conversation

@joshrotenberg
Copy link
Copy Markdown
Owner

Summary

Adds configurable timeout for stop operations during ContainerGuard cleanup/drop.

Closes #221

Changes

  • Add stop_timeout field to GuardOptions (Option<Duration>)
  • Add stop_timeout() builder method to ContainerGuardBuilder
  • Use timeout in Drop implementation for both runtime contexts

API

use docker_wrapper::testing::ContainerGuard;
use docker_wrapper::RedisTemplate;
use std::time::Duration;

// Fast cleanup with 1 second timeout
let guard = ContainerGuard::new(RedisTemplate::new("redis"))
    .stop_timeout(Duration::from_secs(1))
    .start()
    .await?;

// Immediate SIGKILL with zero timeout
let guard = ContainerGuard::new(RedisTemplate::new("redis"))
    .stop_timeout(Duration::ZERO)
    .start()
    .await?;

Use Cases

  • Fast test cleanup with short timeout for containers that don't need graceful shutdown
  • Longer timeout for containers that need time to flush data
  • Zero timeout for immediate SIGKILL

Tests

Added 2 integration tests:

  • test_container_guard_stop_timeout - 1 second timeout
  • test_container_guard_stop_timeout_zero - immediate SIGKILL

Adds stop_timeout option to ContainerGuard for configuring how long
Docker waits before sending SIGKILL during cleanup.

Changes:
- Add stop_timeout field to GuardOptions (Option<Duration>)
- Add stop_timeout() builder method to ContainerGuardBuilder
- Use timeout in Drop implementation for both runtime contexts

Use cases:
- Fast test cleanup with short timeout (e.g., 1 second)
- Longer timeout for containers needing graceful shutdown
- Duration::ZERO for immediate SIGKILL

Example:
  let guard = ContainerGuard::new(template)
      .stop_timeout(Duration::from_secs(1))
      .start()
      .await?;

Closes #221
@joshrotenberg joshrotenberg merged commit 73e61e8 into main Jan 6, 2026
11 checks passed
@joshrotenberg joshrotenberg deleted the feat/container-guard-stop-timeout branch January 6, 2026 00:19
@github-actions github-actions Bot mentioned this pull request Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add configurable timeout for ContainerGuard cleanup

1 participant